//
//  PlayerSettingCell.m
//  SleepingElf
//
//  Created by karong on 2023/10/19.
//

#import "PlayerSettingCell.h"

@interface PlayerSettingCell ()
@property (weak, nonatomic) IBOutlet UISlider *sliderView;
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
@property (nonatomic, strong) MusicModel * music;
@end

@implementation PlayerSettingCell
- (void)awakeFromNib {
    [super awakeFromNib];
    [self.sliderView setThumbImage:SEIMG(@"icon_slider") forState:(UIControlStateNormal)];
}

- (IBAction)sliderChange:(UISlider *)sender {
    NSLog(@"%f", sender.value);
    [[PlayerManager shared]changePlayerVolume:sender.value music:self.music];
}


- (void)setDataWithObject:(id)object {
    [super setDataWithObject:object];
    self.music = object;
    self.sliderView.value = [[PlayerManager shared]playerVolumeWithMusic:object];
}

- (void)setDataImageWithObject:(MusicModel *)object {
    [self setDataWithObject:object];
    [[SDWebImageManager sharedManager] loadImageWithURL:[NSURL URLWithString:object.cover] options:0 progress:^(NSInteger receivedSize, NSInteger expectedSize, NSURL * _Nullable targetURL) {
        } completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, SDImageCacheType cacheType, BOOL finished, NSURL * _Nullable imageURL) {
            if (image) {
                image = [image imageWithRenderingMode:(UIImageRenderingModeAlwaysTemplate)];
                self.imageView.image = image;
                self.imageView.tintColor = [UIColor colorFromHexRGB:@"ffffff"];
            }
        }];
}
@end
